import { defineStore } from "pinia";

export const useUser = defineStore("user", {
  state: () => ({
    isLoggedIn: false,
    user: null,
  }),
  actions: {
    // 读取信息
    login(username, password) {
      if (username === "22001449" && password === "123456") {
        this.isLoggedIn = true;
      } else {
        this.isLoggedIn = false;
        console.log("账号密码不正确，请重新输入");
        alert("账号密码不正确，请重新输入");
      }
    },
    // 注销
    logout() {
      this.user = null;
      this.isLoggedIn = false;
      JSON.parse(localStorage.getItem("username, password"));
    },
  },
});
